<?php
/**
*+-------IMBA后台管理栏目业务数据的存储操作--------+
*+-------------------------------------------------+
*+-----栏目业务是基于MongoDB存储存储视频专题类信息-+
*+-------------------------------------------------+
*+-@author susy.liang <liangling@ilongyuan.com.cn>-+
*+-------------------------------------------------+
*/
namespace Admin\Service;
use \Common\Service\BaseService;

Class TopicService extends BaseService
{
	//id, title(标题), sort(排序),status(状态),
	//create_time(创建时间),update_time(更新时间),
	//videos(首推的视频IDS)

	// 状态
	CONST STATUS_PEDDING = 0;	// 审核 pedding
	CONST STATUS_PASS 	 = 1;	// 展示 pass
	CONST STATUS_DEL  	 = -1;  // 删除 delete

	//ERROR 错误
	CONST ERROR_TITLE 	 = '标题不能为空!';

	//标题不唯一错误
	CONST ERROR_TITLE_UNIQUE	= '标题已存在';


	//自动验证
	protected $_validate = array(
		array('title', 'require', self::ERROR_TITLE, self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
		array('title', '', self::ERROR_TITLE_UNIQUE, self::MUST_VALIDATE , 'unique', self::MODEL_BOTH),
	);

	//自动完成
	protected $_auto = array(
        array('title', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
        array('status', 'intval', self::MODEL_BOTH, 'function'),
        array('web_visible', 'intval', self::MODEL_BOTH, 'function'),
        array('visitor_visible', 'intval', self::MODEL_BOTH, 'function'),
    );

	/**
	*更新栏目推荐的视频信息
	*@param array $data 信息组
	*/
	public function updateVideo($id, $data = ''){
		if($data['videos']){
			$data['videos'] = implode(',', $data['videos']);
			// $data['videos'] = ','.$data['videos'].',';    // 去掉前后的,号
		}
		else
		{
			$data['videos'] = '';
		}
		
		$res = $this->where(array('id'=>$id))->save($data);
		return $res?true:false;

	}

	
}